package cn.johnyu.nacos;

import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;

import java.util.Properties;

public class DiscoveryClientDemo {
    public static void main(String[] args) {
        try {
            String serverAddr = "http://localhost:8848";
            Properties properties = new Properties();
            properties.put("serverAddr", serverAddr);
            properties.put("username", "nacos");
            properties.put("password", "nacos");
            properties.put("namespace", "public");

            NamingService naming = NamingFactory.createNamingService(properties);

            // 注册实例
            naming.registerInstance("my-service3", "DEFAULT_GROUP", "11.11.11.12", 8886,"");
            //发现实例
            Thread.sleep(1000);
            System.out.println("Registered instances: " + naming.getAllInstances("my-service3"));

            System.out.println("服务注册成功，当程序退出时，NamingService会将服务注销，当前程序运行中。。。。");

            System.in.read();
            naming.shutDown();//自动注销服务
//

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
